package com.mark.common.utils;

import com.mark.common.utils.PropertiesUtil;
import com.mark.common.enums.PropertiesEnum;

/**
 * @Description: 路径处理工具类
 * @Author: Mark
 * @CreateDate: 2018/4/12.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
public class PathUtil{

    public static String separator = System.getProperty(PropertiesEnum.FILE_SEPARATOR.getPropertiesName());//获取文件的分流符号
    private static String basePathWin= PropertiesUtil.getProperty(PropertiesEnum.BASE_PATH_WIN.getPropertiesName());
    private static String basePathOther= PropertiesUtil.getProperty(PropertiesEnum.BASE_PATH_OTHER.getPropertiesName());
    private static String productPath= PropertiesUtil.getProperty(PropertiesEnum.PRODUCT_PATH.getPropertiesName());
    private static String categoryPath= PropertiesUtil.getProperty(PropertiesEnum.CATEGORY_PATH.getPropertiesName());
    private static String  headLinePath= PropertiesUtil.getProperty(PropertiesEnum.HEADLINE_PATH.getPropertiesName());
    private static String  simditorPath= PropertiesUtil.getProperty(PropertiesEnum.SIMDITOR_PATH.getPropertiesName());
    private static String  getQrPath= PropertiesUtil.getProperty(PropertiesEnum.getQrPath.getPropertiesName());
    private static String userPath= PropertiesUtil.getProperty(PropertiesEnum.USER_PATH.getPropertiesName());
    private static String fragmentPath = PropertiesUtil.getProperty(PropertiesEnum.FRAGMENT_PATH.getPropertiesName());

    public static String getImageBasePath() {
        String os = System.getProperty("os.name");

        String basePath ;
        if (os.toLowerCase().startsWith("win")) {
            basePath = basePathWin;
        } else {
            basePath = basePathOther;
        }
        basePath = basePath.replace("/", separator);
        return basePath;
    }

    public static String getProductImagePath(long productId) {
        String imagePath = productPath + productId + "/";
        return imagePath.replace("/", separator);
    }

    public static String getUserImageath(long userId){
        String imagePath = userPath + userId + "/";
        return imagePath.replace("/", separator);
    }

    public static String getCategoryImagePath() { //返回商品种类图片保存的路径
        String imagePath = categoryPath + "/";
        return imagePath.replace("/", separator);
    }

    public static String getHeadLineImagePath() { //返回公告信息图片保存的路径

        String imagePath = headLinePath + "/";
        return imagePath.replace("/", separator);
    }

    public static String getSimditorImagePath() { //返回富文本插件中上传图片保存的路径
        String imagePath = simditorPath + "/";
        return imagePath.replace("/", separator);
    }

    /**
     * 获取碎片资源存放的根路径
     * @return ：D:/ftpFile/img/campus/images/fragment/moduleId
     */
    public static String getFragmentPath(String moduleId){
        String fileBasePath = PathUtil.getImageBasePath();
        String imagePath = fileBasePath+fragmentPath +moduleId;
        return imagePath.replace("/", separator);
    }

    //返回二维码的路径
    public static String getQrPath(){
        String imagePath = getQrPath + "/";
        return imagePath.replace("/", separator);
    }


}
